package edu.gdkm.dao;

import edu.gdkm.pojo.Experience;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExperienceDao {

    // 根据ID查询
    @Select("SELECT * FROM Experiences WHERE experience_id = #{experienceId}")
    Experience selectById(Integer experienceId);

    // 根据简历ID查询
    @Select("SELECT * FROM Experiences WHERE resume_id = #{resumeId} ORDER BY start_date DESC")
    List<Experience> selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM Experiences")
    List<Experience> selectAll();

    // 新增
    @Insert("INSERT INTO Experiences(resume_id, company_name, position, start_date, end_date, is_current, description, location) " +
            "VALUES(#{resumeId}, #{companyName}, #{position}, #{startDate}, #{endDate}, #{isCurrent}, #{description}, #{location})")
    @Options(useGeneratedKeys = true, keyProperty = "experienceId")
    int insert(Experience experience);

    // 更新
    @Update("UPDATE Experiences SET resume_id = #{resumeId}, company_name = #{companyName}, position = #{position}, " +
            "start_date = #{startDate}, end_date = #{endDate}, is_current = #{isCurrent}, " +
            "description = #{description}, location = #{location} WHERE experience_id = #{experienceId}")
    int update(Experience experience);

    // 删除
    @Delete("DELETE FROM Experiences WHERE experience_id = #{experienceId}")
    int delete(Integer experienceId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM Experiences WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    